<html>
<body>

<form action = "innerjoin.php" method = "post">
User: <input type = "text" name = "user"/>
<input type = "submit" />
</form>

<?php

//Creates connection, confirms connection. Be sure to fill in the correct user name and password.

$con = mysql_connect("localhost" , "root" , "howdy123");

if (!$con) die ("Could not connect" . mysql_error());
else print "ok";

print "<br>";

//Retrieves user_id from form and prints how many movies they like. Much of this is useless, except for mysql_select_db.

$user = $_POST["user"];

mysql_select_db("db" , $con);

$query = mysql_query("select count(*) from data where user_id = " . $user);

$query = mysql_fetch_array($query);

print $query[0];

//This is the money. It returns a list of users similar to $user. Descending order. Note the first user_id is likely to be $user themself.

$query = mysql_query("select a.user_id as user, count(a.item_id) as b from db.data a inner join db.data b on a.item_id = b.item_id where b.user_id = " . $user . "  and a.rating = b.rating group by a.user_id order by b desc");

//Prints results. I need to add on some already built sql syntax to return movies instead of user_id's.

for ($i = 1; $i <= 5; $i++)
	{
	$query2 = mysql_fetch_array($query);

 	print "<br>";

	print $query2['user'];
	
	print "<br>";
	}

mysql_close($con);

?>

</body>
</html>
